<template>
  <el-form
    ref="formRef"
    v-loading="formLoading"
    :model="formData"
    :rules="formRules"
    label-width="120px"
    :disabled="props.formDatas.type === 'View'"
    style="margin-bottom: 72px"
  >
    <ContentWrapForm :title="'基本信息'">
      <el-form-item></el-form-item>
      <el-form
        label-position="top"
        :inline="true"
        class="demo-form-inline"
        :disabled="props.formDatas.type === 'View'"
      >
        <el-form-item label="模型类别" prop="category">
          <el-select
            v-model="formData.category"
            :disabled="!!formDatas.type"
            clearable
            placeholder="请选择模型类别"
          >
            <el-option
              v-for="dict in categoryOpt"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="数据类型" prop="type">
          <el-select
            v-model="formData.type"
            :disabled="!props.flag || formDatas.type == 'Edit'"
            placeholder="数据类型"
          >
            <el-option
              v-for="dict in typeOpt"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="模型名称" prop="modelName">
          <el-input v-model="formData.modelName" placeholder="请输入模型名称" maxlength="20" />
        </el-form-item>

        <el-form-item label="维护人" prop="userName">
          <el-input v-model="formData.userName" disabled placeholder="维护人" />
        </el-form-item>

        <el-form-item label="维护人单位" prop="deptName">
          <el-input v-model="formData.deptName" disabled placeholder="维护人单位" />
        </el-form-item>
      </el-form>
    </ContentWrapForm>

    <ContentWrapForm :title="'圆模型'" v-if="formData.category == '1'">
      <el-form-item> </el-form-item>

      <el-form-item label=" ">
        <el-col :span="1" class="el-colC">
          <span class="italic">I =</span>
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.longRatio1"
            @input="
              (value) =>
                (formData.longRatio1 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="保留四位小数"
          />
        </el-col>
        <el-col :span="1" class="el-colC">
          <el-icon><Plus /></el-icon>
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.longRatio2"
            @input="
              (value) =>
                (formData.longRatio2 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="保留四位小数"
          />
        </el-col>
        <el-col :span="1" class="el-colC">
          <span class="italic">M</span>
        </el-col>
        <el-col :span="1" class="el-colC">
          <el-icon><Minus /></el-icon>
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.longRatio3"
            @input="
              (value) =>
                (formData.longRatio3 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="保留四位小数"
          />
        </el-col>
        <el-col :span="2">
          <el-select v-model="formData.longSymbol" clearable placeholder="请选择">
            <el-option label="lg" value="lg" />
            <el-option label="ln" value="ln" />
          </el-select>
        </el-col>
        <el-col :span="1" class="el-colC">
          <span> (</span>
        </el-col>
        <el-col :span="1" class="el-colC"> <span class="italic">R</span>+ </el-col>
        <el-col :span="2">
          <el-input
            v-model="formData.longRatio4"
            @input="
              (value) =>
                (formData.longRatio4 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="自然数"
          />
        </el-col>
        <el-col :span="1" class="el-colC">
          <span>)</span>
        </el-col>
      </el-form-item>
      <el-col :span="24">
        <el-form-item label=" ">
          <span class="italic">I </span> 为烈度，<span class="italic">M </span> 为震级，<span
            class="italic"
            >R
          </span>
          为圆半径长度
        </el-form-item>
      </el-col>
    </ContentWrapForm>
    <ContentWrapForm :title="'椭圆模型'" v-if="formData.category == '2'">
      <el-form-item> </el-form-item>
      <el-form-item label="长轴：">
        <el-col :span="1" class="el-colC"> <span class="italic">I</span><sub>a</sub>= </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.longRatio1"
            @input="
              (value) =>
                (formData.longRatio1 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="保留四位小数"
          />
        </el-col>
        <el-col :span="1" class="el-colC">
          <el-icon><Plus /></el-icon>
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.longRatio2"
            @input="
              (value) =>
                (formData.longRatio2 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="保留四位小数"
          />
        </el-col>
        <el-col :span="1" class="el-colC">
          <span class="italic">M</span>
        </el-col>
        <el-col :span="1" class="el-colC">
          <el-icon><Minus /></el-icon>
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.longRatio3"
            @input="
              (value) =>
                (formData.longRatio3 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="保留四位小数"
          />
        </el-col>
        <el-col :span="2">
          <el-select v-model="formData.longSymbol" placeholder="请选择">
            <el-option label="lg" value="lg" />
            <el-option label="ln" value="ln" />
          </el-select>
        </el-col>
        <el-col :span="1" class="el-colC">
          <span> (</span>
        </el-col>
        <el-col :span="1" class="el-colC"> <span class="italic">R</span><sub>a</sub>+ </el-col>
        <el-col :span="2">
          <el-input
            v-model="formData.longRatio4"
            @input="
              (value) =>
                (formData.longRatio4 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="自然数"
          />
        </el-col>
        <el-col :span="1" class="el-colC">
          <span>)</span>
        </el-col>
      </el-form-item>
      <el-form-item label="短轴：">
        <el-col :span="1" class="el-colC"> <span class="italic">I</span><sub>b</sub>= </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.shortRatio1"
            @input="
              (value) =>
                (formData.shortRatio1 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="保留四位小数"
          />
        </el-col>
        <el-col :span="1" class="el-colC">
          <!-- <span class="italic" >+</span> -->
          <el-icon><Plus /></el-icon>
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.shortRatio2"
            @input="
              (value) =>
                (formData.shortRatio2 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="保留四位小数"
          />
        </el-col>
        <el-col :span="1" class="el-colC">
          <span class="italic">M</span>
        </el-col>
        <el-col :span="1" class="el-colC">
          <el-icon><Minus /></el-icon>
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.shortRatio3"
            @input="
              (value) =>
                (formData.shortRatio3 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="保留四位小数"
          />
        </el-col>
        <el-col :span="2">
          <el-select v-model="formData.shortSymbol" placeholder="请选择">
            <el-option label="lg" value="lg" />
            <el-option label="ln" value="ln" />
          </el-select>
        </el-col>
        <el-col :span="1" class="el-colC">
          <span> (</span>
        </el-col>
        <el-col :span="1" class="el-colC"> <span class="italic">R</span><sub>b</sub>+ </el-col>
        <el-col :span="2">
          <el-input
            v-model="formData.shortRatio4"
            @input="
              (value) =>
                (formData.shortRatio4 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
            "
            placeholder="自然数"
          />
        </el-col>
        <el-col :span="1" class="el-colC">
          <span>)</span>
        </el-col>
      </el-form-item>
      <el-col :span="24">
        <el-form-item label=" ">
          <el-col :span="24">
            <span class="italic">I</span><sub>a</sub>、<span class="italic">I</span
            ><sub>b</sub>分别为长短轴烈度，<span class="italic">M</span>为震级，
            <span class="italic">R</span><sub>a</sub>、<span class="italic">R</span
            ><sub>b</sub>分别为烈度为<span class="italic">I</span>时长、短半轴的长度。
          </el-col>
        </el-form-item>
      </el-col>
    </ContentWrapForm>
    <ContentWrapForm :title="'线源模型'" label=" " v-if="formData.category == '3'">
      <el-form-item> </el-form-item>
      <el-col :span="24">
        <el-form-item label="破裂尺度计算公式：" label-width="140px">
          <el-col :span="18">
            <el-form-item label=" " label-width="54px" style="width: 100%">
              <el-col :span="1" class="el-colC"> <span class="italic">M</span>= </el-col>
              <el-col :span="4">
                <el-input
                  v-model="formData.ruptureScale1"
                  @input="
                    (value) =>
                      (formData.ruptureScale1 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="保留四位小数"
                />
              </el-col>
              <el-col :span="1" class="el-colC">
                <el-icon><Plus /></el-icon>
              </el-col>
              <el-col :span="4">
                <el-input
                  v-model="formData.ruptureScale2"
                  @input="
                    (value) =>
                      (formData.ruptureScale2 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="保留四位小数"
                />
              </el-col>
              <el-col :span="1" class="el-colC">
                <span class="italic">lgL</span>
              </el-col>
            </el-form-item>
          </el-col>
        </el-form-item>
      </el-col>
      <el-col :span="24"></el-col>
      <el-col :span="24">
        <el-form-item label="点源影响场公式：" label-width="140px">
          <el-col :span="18">
            <el-form-item label="长轴：" label-width="auto">
              <el-col :span="1" class="el-colC">
                <span class="italic">I</span><sub>a</sub>=
              </el-col>
              <el-col :span="4">
                <el-input
                  v-model="formData.longRatio1"
                  @input="
                    (value) =>
                      (formData.longRatio1 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="保留四位小数"
                />
              </el-col>
              <el-col :span="1" class="el-colC">
                <el-icon><Plus /></el-icon>
              </el-col>
              <el-col :span="4">
                <el-input
                  v-model="formData.longRatio2"
                  @input="
                    (value) =>
                      (formData.longRatio2 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="保留四位小数"
                />
              </el-col>
              <el-col :span="1" class="el-colC">
                <span class="italic">M</span>
              </el-col>
              <el-col :span="1" class="el-colC">
                <el-icon><Minus /></el-icon>
              </el-col>
              <el-col :span="4">
                <el-input
                  v-model="formData.longRatio3"
                  @input="
                    (value) =>
                      (formData.longRatio3 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="保留四位小数"
                />
              </el-col>
              <el-col :span="2">
                <el-select v-model="formData.longSymbol" placeholder="请选择">
                  <el-option label="lg" value="lg" />
                  <el-option label="ln" value="ln" />
                </el-select>
              </el-col>
              <el-col :span="1" class="el-colC">
                <span> (</span>
              </el-col>
              <el-col :span="1" class="el-colC">
                <span class="italic">R</span><sub>a</sub>+
              </el-col>
              <el-col :span="2">
                <el-input
                  v-model="formData.longRatio4"
                  @input="
                    (value) =>
                      (formData.longRatio4 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="自然数"
                />
              </el-col>
              <el-col :span="1" class="el-colC">
                <span>)</span>
              </el-col>
            </el-form-item>
            <el-form-item label="短轴：" label-width="auto">
              <el-col :span="1" class="el-colC">
                <span class="italic">I</span><sub>b</sub>=
              </el-col>
              <el-col :span="4">
                <el-input
                  v-model="formData.shortRatio1"
                  @input="
                    (value) =>
                      (formData.shortRatio1 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="保留四位小数"
                />
              </el-col>
              <el-col :span="1" class="el-colC">
                <!-- <span class="italic" >+</span> -->
                <el-icon><Plus /></el-icon>
              </el-col>
              <el-col :span="4">
                <el-input
                  v-model="formData.shortRatio2"
                  @input="
                    (value) =>
                      (formData.shortRatio2 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="保留四位小数"
                />
              </el-col>
              <el-col :span="1" class="el-colC">
                <span class="italic">M</span>
              </el-col>
              <el-col :span="1" class="el-colC">
                <el-icon><Minus /></el-icon>
              </el-col>
              <el-col :span="4">
                <el-input
                  v-model="formData.shortRatio3"
                  @input="
                    (value) =>
                      (formData.shortRatio3 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="保留四位小数"
                />
              </el-col>
              <el-col :span="2">
                <el-select v-model="formData.shortSymbol" placeholder="请选择">
                  <el-option label="lg" value="lg" />
                  <el-option label="ln" value="ln" />
                </el-select>
              </el-col>
              <el-col :span="1" class="el-colC">
                <span> (</span>
              </el-col>
              <el-col :span="1" class="el-colC">
                <span class="italic">R</span><sub>b</sub>+
              </el-col>
              <el-col :span="2">
                <el-input
                  v-model="formData.shortRatio4"
                  @input="
                    (value) =>
                      (formData.shortRatio4 = value
                        .replace(/[^0-9.]/g, '')
                        .replace(/^(\d+\.\d{0,4}).*$/, '$1'))
                  "
                  placeholder="自然数"
                />
              </el-col>
              <el-col :span="1" class="el-colC">
                <span>)</span>
              </el-col>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label=" " label-width="auto">
              <el-col :span="24">
                L为破裂尺度，
                <span class="italic">I</span><sub>a</sub>、<span class="italic">I</span
                ><sub>b</sub>分别为长短轴烈度，<span class="italic">M</span>为震级，
                <span class="italic">R</span><sub>a</sub>、<span class="italic">R</span
                ><sub>b</sub>分别为烈度为<span class="italic">I</span>时长、短半轴的长度。
              </el-col>
            </el-form-item>
          </el-col>
        </el-form-item>
      </el-col>
    </ContentWrapForm>
    <ContentWrapForm :title="'触发条件'" :pcontent="'（从下面的两个条件中至少选填一项）'">
      <el-form-item> </el-form-item>

      <el-form-item label="震级范围:">
        <el-col :span="4">
          <el-input
            v-model="formData.earthQuakeLevel1"
            @input="
              (value) =>
                (formData.earthQuakeLevel1 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,1}).*$/, '$1'))
            "
            placeholder="请输入"
          />
        </el-col>
        <el-col :span="3">
          <el-select v-model="formData.earthQuakeLevelSymbol" placeholder="请选择">
            <el-option
              v-for="dict in earthQuakeOpt"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-col>
        <el-col :span="2" class="el-colC"> 震级 </el-col>
        <el-col :span="3">
          <el-select v-model="formData.earthQuakeLevelSymbol1" placeholder="请选择状态">
            <el-option
              v-for="dict in earthQuakeOpt1"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="formData.earthQuakeLevel2"
            @input="
              (value) =>
                (formData.earthQuakeLevel2 = value
                  .replace(/[^0-9.]/g, '')
                  .replace(/^(\d+\.\d{0,1}).*$/, '$1'))
            "
            placeholder="请输入"
          />
        </el-col>
      </el-form-item>
      <el-col :span="24">
        <el-form-item label="适用区域:" prop="scope">
          <!-- <el-radio-group > -->
          <el-radio
            v-model="formData.scope"
            key="2"
            :value="2"
            @click.native.prevent="radioChange(2)"
            >上传区域文件</el-radio
          >
          <el-radio
            v-model="formData.scope"
            key="1"
            :value="1"
            @click.native.prevent="radioChange(1)"
            >按行政区域选择</el-radio
          >
          <!-- </el-radio-group> -->
          <ProvinceCity
            ref="provinceRef"
            :regionLists="formData.regionList"
            @querySelect="querySelect"
          ></ProvinceCity>
        </el-form-item>
      </el-col>
      <el-col :span="24" v-if="formData.scope == 1">
        <el-form-item label=" ">
          {{ regionLists }}
        </el-form-item>
      </el-col>
      <el-col :span="24" v-show="formData.scope == 2">
        <el-form-item label=" ">
          <!-- <UploadImgs v-model="formData.voList" /> -->
          <UploadFileTo
            v-model="formData.voList"
            :updateUrl="updateUrl"
            :disabled="disabled"
            @uploadSuccess="uploadSuccess"
            :updateData="{ type: formData.type }"
          />
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label=" ">
          <el-col :span="12" style="height: 400px">
            <LoadMap :fileidInfo="fileidInfo" style="height: 100%" />
          </el-col>
        </el-form-item>
      </el-col>
    </ContentWrapForm>
  </el-form>

  <el-col :span="24" class="el-colfoot">
    <el-button @click="handClose">关 闭</el-button>
    <el-button
      :disabled="formLoading"
      type="primary"
      v-if="props.formDatas.type !== 'View'"
      @click="submitForm"
      >保 存</el-button
    >
  </el-col>
</template>
<script lang="ts" setup>
import { getUserProfile } from '@/api/system/user/profile'
import { saveOrCopyModel, updateModel, getByIdModel, saveTempData } from '@/api/template'
import UploadFileTo from '@/views/responseLevel/populationDensity/create/UploadFile.vue'
import ProvinceCity from '@/views/responseLevel/populationDensity/create/provinceCity.vue'
import { useUserStore } from '@/store/modules/user'

import LoadMap from '@/views/earthquake/earthquakeServer/gis/LoadMap.vue'
defineOptions({ name: 'templateAdd' })
const getUserInfos = useUserStore().getUserInfo

const props = defineProps({
  formDatas: {
    // 流程实例的数据。传递时，可展示流程发起人等信息
    type: Object,
    default: () => {}
  },
  flag: {
    type: Boolean,
    default: false
  }
})
const emit = defineEmits(['success', 'setClose']) // 定义 success 事件，用于操作成功后的回调
const setClose = () => {
  emit('setClose')
}

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const updateUrl = ref(import.meta.env.VITE_BASE_URL + '/admin-api/attachment/uploadShpFile1')
const provinceRef = ref()
const disabled = props.formDatas.type === 'View' // 查看禁用
const TmapDivRef = ref()

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formData: any = ref({
  id: '',
  category: '1',
  type: '1',
  modelName: '',
  userId: '',
  userName: '22',
  deptId: '',
  deptName: '222',
  longRatio1: '',
  longRatio2: '',
  longRatio3: '',
  longRatio4: '',
  longSymbol: 'lg',
  shortRatio1: '',
  shortRatio2: '',
  shortRatio3: '',
  shortRatio4: '',
  shortSymbol: 'lg',
  earthQuakeLevel1: '',
  earthQuakeLevel2: '',
  earthQuakeLevelSymbol: '1',
  earthQuakeLevelSymbol1: '1',
  scope: null,
  regionList: [],
  voList: [],
  ruptureScale1: '',
  ruptureScale2: '',
  level: ''
})
const resetForm = ref({
  id: '',
  category: '1',
  type: '1',
  modelName: '',
  userId: '',
  userName: '22',
  deptId: '',
  deptName: '222',
  longRatio1: '',
  longRatio2: '',
  longRatio3: '',
  longRatio4: '',
  longSymbol: 'lg',
  shortRatio1: '',
  shortRatio2: '',
  shortRatio3: '',
  shortRatio4: '',
  shortSymbol: 'lg',
  earthQuakeLevel1: '',
  earthQuakeLevel2: '',
  earthQuakeLevelSymbol: '1',
  earthQuakeLevelSymbol1: '1',
  scope: null,
  regionList: [],
  voList: [],
  ruptureScale1: '',
  ruptureScale2: '',
  level: ''
})
const formRules = reactive({
  category: [{ required: true, message: '模型类别不能为空', trigger: 'change' }],
  type: [{ required: true, message: '数据类型不能为空', trigger: 'change' }],
  modelName: [{ required: true, message: '模型名称不能为空', trigger: 'blur' }],
  userName: [{ required: true, message: '维护人不能为空', trigger: 'blur' }],
  deptName: [{ required: true, message: '维护人单位不能为空', trigger: 'blur' }],
  status: [{ required: true, message: '岗位状态不能为空', trigger: 'change' }],
  remark: [{ required: false, message: '岗位内容不能为空', trigger: 'blur' }]
})
const formRef = ref() // 表单 Ref
const categoryOpt = ref([
  { label: '圆模型', value: '1' },
  { label: '椭圆模型', value: '2' },
  { label: '线源模型', value: '3' }
]) // //1、圆模型  2、椭圆模型  3、线源模型
const typeOpt = ref([
  { label: '公用', value: '1' },
  { label: '专用', value: '2' }
]) //1 公用  2私有
const earthQuakeOpt = ref([
  { label: '≤', value: '1' },
  { label: '<', value: '2' }
]) //1 公用  2私有
const earthQuakeOpt1 = ref([
  { label: '≤', value: '1' },
  { label: '<', value: '2' },
  { label: '=', value: '3' }
]) //1 公用  2私有

const regionLists = ref('')

//初始化 type 0 -- 临时表 1 ---正式表 owner public公库 private专库
const fileidInfo = ref({
  fileid: '',
  type: 0,
  query: {
    tableName: 'temp_file_data',
    fields: 'id',
    owner: 'public'
  }
})

const clickRadio = () => {
  if (props.formDatas.type !== 'View') {
    provinceRef.value.open()
    formData.value.voList = []
  }
}

const clickClose = () => {
  provinceRef.value?.close()
}
const radioChange = (v) => {
  formData.value.scope =
    formData.value.scope == v ? (formData.value.scope = '') : (formData.value.scope = v)

  if (formData.value.scope == 1) {
    clickRadio()
  } else {
    clickClose()
  }
}
const querySelect = (value) => {
  getRegionList(value)
}
//回显行政数据
const getRegionList = async (value) => {
  let data: any = []
  value.forEach((item) => {
    if (item.city) {
      data.push(item.province + '-' + item.city)
    } else {
      data.push(item.province)
    }
  })
  let params = {
    city: data.join(','),
    type: formData.value.type
  }
  const res: any = await saveTempData(params)
  //res.id  返回的城市id
  regionLists.value = res.city

  formData.value.regionList = value //data.join(',');
  initFileInfo(false)
  fileidInfo.value.fileid = res.id
}
// 上传成功
const uploadSuccess = (value) => {
  formData.value.voList = value
  // TmapDivRef.value.setLay('circle',[]);
  initFileInfo(false)
  fileidInfo.value.fileid = value[0].id
}
/** 提交表单 */
const submitForm = async () => {
  // 校验表单
  if (!formRef) return
  const valid = await formRef.value.validate()
  if (!valid) return
  // 提交请求
  formLoading.value = true
  try {
    const data = formData.value
    if (data.earthQuakeLevel1 && data.earthQuakeLevel2) {
      if (data.earthQuakeLevel2 < data.earthQuakeLevel1) {
        message.info('震级范围第二个参数必须大于第一个参数')
        return false
      }
    }
    if (props.formDatas.type === 'Edit') {
      await updateModel(data)
      message.success(t('common.updateSuccess'))
      handClose()
    } else {
      await saveOrCopyModel(data)
      message.success(t('common.createSuccess'))
      formData.value = { ...resetForm.value }
      handClose()
    }
  } finally {
    formLoading.value = false
  }
}
/** 关闭操作 */
const handClose = () => {
  setClose()
}
const getFormdata = async () => {
  if (props.formDatas.id) {
    let param = {
      modelId: props.formDatas.id,
      type: props.formDatas.dtype,
      divisionId: props.formDatas.divisionId
    }
    const res = await getByIdModel(param)
    if (!res.voList) {
      res.voList = []
    }
    if (props.formDatas.type === 'Copy') {
      res.modelName = res.modelName + 'Copy'
      if (
        getUserInfos.roles.some(
          (item) =>
            item.name == '超级管理员' ||
            item.name == '国家级管理员' ||
            item.name == '国家级业务人员'
        )
      ) {
        res.level = '1'
        res.type = '1'
      } else {
        res.level = '2'
        res.type = '2'
      }
      res.earthQuakeLevel1 = null
      res.earthQuakeLevel2 = null
      res.scope = null
      res.regionList = null
      res.voList = []
    }
    if (res.scope == '2') {
      res.voList.forEach((item) => {
        item.name = item.attachName
        item.url = item.attachPath
      })
    }

    if (res.regionList && res.regionList.length > 0) {
      let data: any = []
      res.regionList.forEach((item) => {
        if (item.city) {
          data.push(item.province + '-' + item.city)
        } else {
          data.push(item.province)
        }
      })
      regionLists.value = data.join(',')
    } else {
      res.regionList = []
    }

    formData.value = { ...res }
    if (props.formDatas.type == 'Copy') {
      if (!props.flag) {
        formData.value.level = '2'
        formData.value.type = '2'
      } else {
        formData.value.level = '1'
        formData.value.type = '1'
      }
    }
  } else {
    if (!props.flag) {
      formData.value.level = '2'
      formData.value.type = '2'
    } else {
      formData.value.level = '1'
      formData.value.type = '1'
    }
  }
}

const getUserInfo = async () => {
  const res = await getUserProfile()
  formData.value.userId = res.id
  formData.value.userName = res.nickname
  formData.value.deptId = res.deptId
  formData.value.deptName = res.dept.name
}

const init = async () => {
  console.log('props.formDatas', props.formDatas)

  if (props.formDatas.type != 'View' || !props.formDatas.type) {
    getUserInfo()
  }
  getFormdata()
}

const initFileInfo = (flag) => {
  // var flag = props.formDatas.type == "Edit" ? true : false;
  var obj = {
    fileid: !flag ? '' : props.formDatas.id,
    type: !flag ? 0 : 1,
    query: {
      tableName: !flag ? 'temp_file_data' : 'basic_model_shp',
      fields: !flag
        ? 'id'
        : 'id,province,city,full_name,create_user,create_time,del_flag,model_id,source,code',
      owner: formData.value.type == '1' ? 'public' : 'private'
    }
  }
  if (flag) {
    obj.query.filter = `model_id='${props.formDatas.id}'`
  }
  fileidInfo.value = obj
}

onMounted(async () => {
  await init()
  if (props.formDatas.type == 'Edit' || props.formDatas.type == 'View') {
    initFileInfo(true)
  }
})
</script>
<style lang="scss" scoped>
.italic {
  font-style: italic;
  font-size: 16px;
  font-weight: 400;
  margin-right: 5px;
}
.el-colC {
  text-align: center;
}
.el-colfoot {
  position: absolute;
  left: 0px;
  width: 100%;
  height: 72px;
  opacity: 1;
  bottom: 0;
  background: #ffffff;
  box-sizing: border-box;
  border: 0.5px solid #ffffff;
  text-align: right;
  padding: 20px;
}
.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.demo-form-inline .el-select {
  --el-select-width: 220px;
}
</style>